package com.company;
import java.util.Arrays;
/**
 * @author zhf
 * @date 2021/10/8
 */

/**
 * 最长回文子串
 */
public class longestString {
    /*
向两边扩散
 */
    private int expandAroundCenter(String s, int left, int right) {
        int L = left, R = right;
        while (L >= 0 && R < s.length() && s.charAt(L) == s.charAt(R)) {
            L--;
            R++;
        }
        return R - L - 1;
    }
/*
求最长回文子串
 */
    public String longestPalindrome(String s) {
        int len = s.length();
        int start = 0;
        int end = 0;
        /*
        字符串为空返回空字符串
         */
        if (s == null || len < 1 ) {
            return "";
        }

        for (int i = 0; i < len; i++) {
            int len1 = expandAroundCenter(s,i,i);
            int len2 = expandAroundCenter(s,i,i+1);
            int maxlen = Math.max(len1,len2);
            if (maxlen > end - start) {
                start = i - (maxlen - 1) / 2;
                end = i + maxlen / 2;
            }

        }
        return s.substring(start, end + 1);

    }


        public static void main(String[] args) {
        String s = "babad";
//        char[] t = new  longestString(s);
        System.out.println("args = ");
    }
}
